<template>
  <div class="hello">
    <KeepAlive :include="['goods']">
      <component :is="currentComponent"></component>
    </KeepAlive>
    <button @click="changeComponent">切换</button>
  </div>
</template>

<script lang="ts" setup>
import { ref, onUnmounted } from "vue";
import Goods from "./test/goods.vue";
import Foods from "./test/foods.vue";

let currentComponent = ref(Goods);

const changeComponent = () => {
  currentComponent.value =
    currentComponent.value.name === "goods" ? Foods : Goods;
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
